﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

namespace YXShop.Web.membercenter.shop.shop_administer
{
    public partial class shop_order_list : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                GetList();
                InitWebControls();
            }
        }

        private void InitWebControls()
        {
            ChangeHope.WebPage.WebControl.SetDate(this.w_g_OrderDate);
            this.Form.Attributes.Add("onsubmit", "return CheckForm();");
            
        }

        private void GetList()
        {
            YXShop.BLL.Order.Orders bll = new YXShop.BLL.Order.Orders();
            YXShop.BLL.Shop.Shop shopBll = new YXShop.BLL.Shop.Shop();
            List<YXShop.Model.Shop.Shop> shopList=new List<YXShop.Model.Shop.Shop>();
            ChangeHope.DataBase.DataByPage datapage = new ChangeHope.DataBase.DataByPage();
            if (Session["MemberID"]!=null)
            {
                shopList = shopBll.GetListShopByWhere(" uid=" + Session["MemberID"].ToString());
                if (shopList != null)
                {
                    datapage = bll.GetList(" [order by] OrderDate desc", 20, " and BusinessmanID=" + shopList[0].Sid.ToString() + " ");
                }
            }       
            ChangeHope.WebPage.Table table = new ChangeHope.WebPage.Table();
            YXShop.Common.OrdersStatusEnum ose = new YXShop.Common.OrdersStatusEnum();
            table.AddHead("&nbsp;/,订单号/,用户名/,下单时间/,商品金额/,<img src=\"..\\..\\..\\images\\dot.gif\" title=\"订单金额=商品总价+运费+支付手续费\" >订单金额/,订单状态/,付款状态/,物流状态/");
            int index = 0;
            if (datapage.DataReader != null)
            {
                while (datapage.DataReader.Read())
                {
                    index++;
                    table.AddCol((datapage.PageCount * (datapage.PageIndex - 1) + index).ToString());
                    string TypeStr = string.Empty;
                    if (datapage.DataReader["OrderType"].ToString() == "1")
                    {
                        TypeStr = "<span style='color:red'>拍</span>";
                    }
                    else if (datapage.DataReader["OrderType"].ToString() == "2")
                    {
                        TypeStr = "<span style='color:red'>团</span>";
                    }
                    string url = YXShop.TemplateAction.Common.UrlStr("shop_order_edit", "OrderId=" + datapage.DataReader["Id"].ToString(), "membercenter/shop/shop_administer/");
                    table.AddCol(TypeStr + "<a href=\""+url+"\">" + datapage.DataReader["OrderId"].ToString() + "</a>");
                    table.AddCol("<span title='" + datapage.DataReader["UserId"].ToString() + "'>" + ChangeHope.Common.StringHelper.SubString(datapage.DataReader["UserId"].ToString(), 10) + "</span>");
                    table.AddCol(datapage.DataReader["OrderDate"].ToString());
                    table.AddCol("￥" + Convert.ToDouble(datapage.DataReader["TotalPrice"].ToString()).ToString("f2") + " 元");
                    table.AddCol("￥" + Convert.ToDouble(datapage.DataReader["FactPrice"].ToString()).ToString("f2") + " 元");
                    table.AddCol(ose.OrderStatus(int.Parse(datapage.DataReader["OrderStatus"].ToString())));
                    table.AddCol(ose.PaymentStatus(int.Parse(datapage.DataReader["PaymentStatus"].ToString())));
                    table.AddCol(ose.OgisticsStatu(int.Parse(datapage.DataReader["OgisticsStatus"].ToString())));
                    table.AddRow();
                }
            }

            this.ltlView.Text = table.GetTable() + datapage.PageToolBar;
            table = null;
            datapage.Dispose();
            datapage = null;
            bll = null;

        }
        protected void btnOk_Click(object sender, EventArgs e)
        {
            this.GetList();
        }
    }
}
